import { reactive } from 'vue'
import { FormRules } from 'element-plus'
export const correctCode = '1234'
function phone(rules: any, value: any, callback: any) {
  if (value === '') {
    callback(new Error('请输入手机号'))
  } else if (value.length !== 11) {
    callback(new Error('请输入正确的手机号'))
  } else {
    callback()
  }
}
function verificationCode(rules: any, value: any, callback: any) {
  if (value === '') {
    callback(new Error('请输入验证码'))
  } else if (value != correctCode || value.length > 4) {
    callback(new Error('请输入正确的验证码'))
  } else {
    callback()
  }
}
export const phoneRules = reactive<FormRules>({
  phone: [
    { validator: phone, trigger: 'blur', required: true },
    { pattern: /^(?:(?:\+|00)86)?1[3-9]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' }
  ],
  verificationCode: [{ validator: verificationCode, trigger: 'blur', required: true }]
})
